*************************
** Replication files for: 
** Deadly Populism:How Local Political Outsiders Drive Duterte’s War on Drugs in the Philippines
** Journal of Politics
** Ravanilla, Sexton and Haim
** October 2020
*************************

clear
set more off

***** Change this file path to the appropriate location
*cd "~/Downloads/"
cd "~/Dropbox/HRS Drug War/1. Data/Replication files"
** 

capture net install st0366.pkg, from("http://www.stata-journal.com/software/sj14-4") force
capture net install st0522.pkg, from("http://www.stata-journal.com/software/sj18-1")
capture ssc install ritest

***

use "RSH-main.dta",clear

***************
** RESULTS
***************

** TABLE 3: BANTAY KRIMEN

eststo clear
foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap interaction postduterte if tight==1, fe vce(cl municipality)
eststo
}

foreach y in drug_related assault theft total_nodrug {
rdrobust `y'_pcap_diff unaligned_vote_share_margin , all
eststo
}

esttab  using "table3.tex", rename(Bias-corrected rdd_estimate interaction DiD_estimate) keep(DiD_estimate rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
  scalars("N N" "N_clust Clusters" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** TABLE 4: ACLED

eststo clear
foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2  {
xtreg `y' interaction postduterte if tight==1, fe vce(cl municipality)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2 {
rdrobust `y'_diff unaligned_vote_share_margin , all
eststo
}

esttab  using "table4.tex", rename(Bias-corrected rdd_estimate interaction DiD_estimate) keep(DiD_estimate rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
  scalars("N N" "N_clust Clusters" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 
  
*** TABLE 5: PROCUREMENT

eststo clear
foreach x in amount_pcap_M horizonal_pcap_M vertical_pcap_M  {
xtreg `x' interaction  postduterte  if tight==1, fe vce(cl municipality)
eststo
}
	
foreach x in amount_pcap_M horizonal_pcap_M vertical_pcap_M  {
rdrobust `x'_diff unaligned_vote_share_margin, all
eststo
}

esttab  using "table5.tex", rename(Bias-corrected rdd_estimate interaction DiD_estimate) keep(DiD_estimate rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50)

*** TABLE 6: 2019 ELECTION

eststo clear
foreach x in incumbent_vote_share_diff switched_party switched_to_pdp pdp_is_winner {
rdrobust `x' unaligned_vote_share_margin, all
eststo
}

esttab  using "table6.tex", rename(Bias-corrected rdd_estimate) keep(rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 


******************
*** DESCRIPTIVES
******************

*** FIGURE 3: Drug-related Police Blotter Reports (Nationwide)

use "figure3_data",clear

   twoway lowess drug_related date if modate>=674 & date<21549,  bw(.1) lcolor(green) lwidth(thick) xline(20604, lwidth(medium) lcolor(navy)) xline(20745,lwidth(medium) lcolor(navy)) ///
   xline(20910,lwidth(medium) lcolor(navy))  xline(21088,lwidth(medium) lcolor(navy))   ///
 legend( order(1 2) label(1 "Drug-related")) xtitle("") /* title("Drug-related Crimes via Police Blotter") */ ///
 text(275 20670 "Duterte") text(260 20670 "- Transition")  text(245 20670 "Begins")  text(275 20820 "Jee Ick-joo") ytitle("")  text(260 20820 "- Kidnapping")text(245 20820 "(pause)")  ///
 text(100 20960 "- {it:Double}" ) text(85 20970 "{it:Barrel}" )  text(70 20970 "{it:Reloaded}")  text(275 21175 "Pause of") text(260 21175 "- {it:Double Barrel}") ///
 xlabel(20604 "Jun 2016" 20745 "Oct 2016" 20910 "Apr 2017" 21088 "Oct 2017" 21275 "Apr 2018") xsize(8.25) ysize(6)
  graph export "desc1.pdf", as(pdf)  replace


*** FIGURE 4: Tests of Politician Sorting

*Note: Need to install DCdensity.ado file from http://eml.berkeley.edu/~jmccrary/DCdensity/DCdensity.ado
use "RSH-main.dta",clear
preserve
DCdensity unaligned_vote_share_margin, breakpoint(0) generate (Xj Yj r0 fhat se_fhat) graphname(forcing_var_test.pdf)
restore

hist unaligned_vote_share_margin ,  width(.04) xline(0) start(-1) xtitle("Outsider Mayor Vote Share Margin")/* title("Density of Outsider Mayor Margins vs. LP") */ percent
 graph export "density1.pdf", as(pdf) replace

*** FIGURE 5: Police Blotter Reports

use "figure5_data",clear

twoway lowess drug_related_pcap modate if non_establishment_mayor==1 & modate>=674 , bw(.6) lcolor(blue) lwidth(thick) ///
 || lowess drug_related_pcap modate if non_establishment_mayor==0 & modate>=674 , bw(.6) lcolor(red) lwidth(thick) xline(677, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" ))  ylabel(0(1)5)  xtitle("Month") ///
 title("Drug-Related") ytitle("Crimes per 1,000 registered voters") ///
 text(2 681 "- Duterte Takes Office") /// 
 xlabel(677 "Jul 2016" 683 "Jan 2017" 689 "Jul 2017" 695 "Jan 2018" 701 "Jul 2018" ) xsize(8.25) ysize(6)
 graph export "chart1.pdf", as(pdf) replace
 
twoway lowess total1_pcap modate if non_establishment_mayor==1 & modate>=674 , bw(.6) lcolor(blue) lwidth(thick) ///
 || lowess total1_pcap modate if non_establishment_mayor==0 & modate>=674 , bw(.6) lcolor(red) lwidth(thick) xline(677, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" )) ylabel(0(5)25)  xtitle("Month") ///
 title("Total Reports")  ytitle("Total Crime per 1,000 registered voters") ///
 text(10 681 "- Duterte Takes Office") ///
 xlabel(677 "Jul 2016" 683 "Jan 2017" 689 "Jul 2017" 695 "Jan 2018" 701 "Jul 2018" ) xsize(8.25) ysize(6)
  graph export "chart2.pdf", as(pdf) replace
  
 *** FIGURE A.2:
 
  twoway lowess violent_pcap modate if non_establishment_mayor==1 & modate>=674 , bw(.6) lcolor(blue) lwidth(thick) ///
 || lowess violent_pcap modate if non_establishment_mayor==0 & modate>=674 , bw(.6) lcolor(red) lwidth(thick) xline(677, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" )) ylabel(0(5)15)   xtitle("Month") ///
 /* title("Violent Crime in Police Blotter")*/ ytitle("Violent Crime per 1,000 registered voters") ///
 text(5 681 "- Duterte Takes Office") ///
 xlabel(677 "Jul 2016" 683 "Jan 2017" 689 "Jul 2017" 695 "Jan 2018" 701 "Jul 2018" ) xsize(8.25) ysize(6)
  graph export "chart3.pdf", as(pdf) replace
  
  
  *** FIGURE A.5 & A.6

sort modate
twoway lowess drug_related_pcap modate if non_establishment_mayor==1 & modate>=672 & modate<=678  , lcolor(blue) lwidth(thick) ///
 || lowess drug_related_pcap modate if non_establishment_mayor==0  & modate>=672 & modate<=678 , lcolor(red) lwidth(thick) xline(678, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" )) ylabel(0(5)15)  xtitle("Month") ///
 title("") ytitle("Drug Crime per 1,000 registered voters") ///
 text(10 681 "- Duterte Takes Office") ///
  xlabel(672 "Jan 2016" 675 "Apr 2016 "678 "Jul 2016") xsize(8.25) ysize(6)
    graph export "pretrends_drug.pdf", as(pdf) replace
  
twoway lowess total1_pcap modate if non_establishment_mayor==1 & modate>=672 & modate<=678  , lcolor(blue) lwidth(thick) ///
 || lowess total1_pcap modate if non_establishment_mayor==0  & modate>=672 & modate<=678 , lcolor(red) lwidth(thick) xline(678, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" )) ylabel(0(5)30)  xtitle("Month") ///
 title("") ytitle("Total Crime per 1,000 registered voters") ///
 text(10 681 "- Duterte Takes Office") ///
  xlabel(672 "Jan 2016" 675 "Apr 2016 "678 "Jul 2016") xsize(8.25) ysize(6)
   graph export "pretrends_total.pdf", as(pdf) replace
 

*** FIGURE 6: RDD plots for Police Blotter Reports and ACLED PNP Fatal Incidents

use "RSH-main.dta",clear

twoway lpolyci drug_related_pcap_diff unaligned_vote_share_margin if unaligned_vote_share_margin<0 & unaligned_vote_share_margin>-.2, pw(.4)  k(epan2) level(80) || ///
lpolyci drug_related_pcap_diff unaligned_vote_share_margin if  unaligned_vote_share_margin>0 & unaligned_vote_share_margin<.2, pw(.4) k(epan2) xline(0) level(80) ///
legend(order(2 1 ) label(2 "Local linear polynomial trend") label(1 "Confidence interval" )) xtitle("Margin of victory (Outsider candidate)") ytitle("Drug-related incidents per capita (differenced)") title("Drug-related")
graph export "drugrelated_rdd.pdf", as(pdf) replace

twoway lpolyci fatal_pnp2_diff unaligned_vote_share_margin if unaligned_vote_share_margin<0 & unaligned_vote_share_margin>-.2, pw(.4)  k(epan2) level(80) || ///
lpolyci fatal_pnp2_diff unaligned_vote_share_margin if  unaligned_vote_share_margin>0 & unaligned_vote_share_margin<.2, pw(.4) k(epan2) xline(0) level(80) ///
legend(order(2 1 ) label(2 "Local linear polynomial trend") label(1 "Confidence interval" )) xtitle("Margin of victory (Outsider candidate)") ytitle("Fatal PNP incidents (differenced)") title("Fatal PNP incidents")
graph export "acledpnp_rdd.pdf", as(pdf) replace

 
*** FIGURE 7: Public Works Procurement Amounts Per Month

use "figure7_data",clear

twoway lowess amount_pcap_M modate if non_establishment_mayor==1 & modate>=674 & modate<=702  ,  lcolor(blue) lwidth(thick) ///
 || lowess amount_pcap_M modate if non_establishment_mayor==0 & modate>=674 & modate<=702  , lcolor(red) lwidth(thick) xline(677, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" ))  xtitle("Month") ///
 title("All Public Works") ytitle("Million PHP per 1,000 adults") ///
 text(35 681 "- Duterte Takes Office") /// 
 xlabel(677 "Jul 2016" 683 "Jan 2017" 689 "Jul 2017" 695 "Jan 2018" 701 "Jul 2018" ) xsize(8.25) ysize(6)  ylabel(0(10)50)
 graph export "procurement1.pdf", as(pdf) replace
 
twoway lowess horizonal_pcap_M modate if non_establishment_mayor==1 & modate>=674 & modate<=702  ,  lcolor(blue) lwidth(thick) ///
 || lowess horizonal_pcap_M modate if non_establishment_mayor==0 & modate>=674 & modate<=702  , lcolor(red) lwidth(thick) xline(677, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" ))  xtitle("Month") ///
 title("Roads & Flood Abatement") ytitle("Million PHP per 1,000 adults") ///
 text(35 681 "- Duterte Takes Office") /// 
 xlabel(677 "Jul 2016" 683 "Jan 2017" 689 "Jul 2017" 695 "Jan 2018" 701 "Jul 2018" ) xsize(8.25) ysize(6)  ylabel(0(10)50)
  graph export "procurement2.pdf", as(pdf) replace
 
twoway lowess vertical_pcap_M modate if non_establishment_mayor==1 & modate>=674 & modate<=702  ,  lcolor(blue) lwidth(thick) ///
 || lowess vertical_pcap_M modate if non_establishment_mayor==0 & modate>=674 & modate<=702  , lcolor(red) lwidth(thick) xline(677, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" ))  xtitle("Month") ///
 title("Schools & Health Facilities") ytitle("Million PHP per 1,000 adults") ///
 text(35 681 "- Duterte Takes Office") /// 
 xlabel(677 "Jul 2016" 683 "Jan 2017" 689 "Jul 2017" 695 "Jan 2018" 701 "Jul 2018" ) xsize(8.25) ysize(6)  ylabel(0(10)50)
 graph export "procurement3.pdf", as(pdf) replace
 
 
*** FIGURE A.6: Pre-trends

twoway lowess amount_pcap_M modate if non_establishment_mayor==1 & modate>=672  & modate<=678, bw(1) lcolor(blue) lwidth(thick) ///
 || lowess amount_pcap_M modate if non_establishment_mayor==0  & modate>=672 & modate<=678, bw(1)  lcolor(red) lwidth(thick) xline(678, lwidth(thick)) ///
 legend( order(1 2) label(1 "Outsider Mayor") label(2 "Liberal Party Mayor" ))   xtitle("Month") ///
 title("") ytitle("Procurement (millions) per 1,000 registered voters") ///
 text(10 681 "- Duterte Takes Office") ///
 xlabel(672 "Jan 2016" 675 "Apr 2016 "678 "Jul 2016") xsize(8.25) ysize(6)
   graph export "pretrends_procurement1.pdf", as(pdf) replace
   

******************
*** APPENDIX
******************

use "RSH-main.dta",clear

*** Table A.1 All crime types: DiD

eststo clear
foreach y in drug_related homicide car_theft assault rape robbery theft car_accident violent {
xtreg `y'_pcap interaction postduterte non_establishment_mayor if tight==1, fe vce(cl municipality)
eststo
}
esttab  using "appendix1.tex", rename(interaction DiD_estimate)  keep(DiD_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 


*** Table A.2 All crime types: RDD

eststo clear
foreach y in drug_related homicide car_theft assault rape robbery theft car_accident violent {
rdrobust `y'_pcap_diff unaligned_vote_share_margin , all
eststo
}
esttab  using "appendix2.tex", rename(Bias-corrected rdd_estimate) keep(rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.3 ACLED fatalities: DiD

eststo clear
foreach y in ihs_fatalities_acled ihs_fatalities_pnp ihs_fatalities_vigilante    {
xtreg `y' interaction postduterte if tight==1, fe vce(cl municipality)
eststo
}

esttab  using "appendix3.tex", rename(interaction DiD_estimate) keep(DiD_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters" )  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.4 Procurement category details: DiD

eststo clear
foreach x in amount amount_road amount_flood amount_school amount_health  {
xtreg `x'_pcap_M interaction  postduterte  if tight==1, fe vce(cl municipality)
eststo
	}
	
esttab  using "appendix4.tex", rename(interaction DiD_estimate) keep(DiD_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.5 Procurement category details: RDD

eststo clear
foreach x in amount amount_road amount_flood amount_school amount_health  {
rdrobust `x'_pcap_M_diff unaligned_vote_share_margin, all
eststo
	}
	
esttab  using "appendix5.tex", rename(Bias-corrected rdd_estimate) keep(rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

eststo clear
foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap interaction postduterte if tight==1 & party!="PDPLBN" , fe vce(cl municipality)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2     {
xtreg `y' interaction postduterte  if tight==1 & party!="PDPLBN" , fe vce(cl municipality)
eststo
}

esttab  using "appendix6.tex", rename(interaction DiD_estimate) keep(DiD_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.7 Pre-Duterte ACLED (binary and fatalities) Placebo: DiD & RDD

eststo clear
foreach y in fatal_acled2 ln_fatalities_acled  {
reg `y' non_establishment_mayor  i.region2   if tight==1 & postduterte==0, robust
eststo
}

foreach y in fatal_acled2 ln_fatalities_acled {
rdrobust `y' unaligned_vote_share_margin if postduterte==0 , all
eststo
}

esttab  using "appendix7.tex", rename(Bias-corrected rdd_estimate) keep(non_establishment_mayor rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.8 Pre-Duterte Procurement Placebo: DiD & RDD

eststo clear
foreach y in amount_pcap_M horizonal_pcap_M vertical_pcap_M  {
reg `y' non_establishment_mayor  i.region2  if tight==1 & postduterte==0, robust
eststo
}
	
foreach y in amount_pcap_M horizonal_pcap_M vertical_pcap_M  {
rdrobust `y' unaligned_vote_share_margin if postduterte==0 , all
eststo
}

esttab  using "appendix8.tex", rename(Bias-corrected rdd_estimate non_establishment_mayor ols_estimate) keep(ols_estimate rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 


*** Table A.9: Null Effects in Non-competitive Municipalities
*** 

eststo clear
foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap interaction postduterte if tight==0, fe vce(cl municipality)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2  {
xtreg `y' interaction postduterte if tight==0 , fe vce(cl municipality)
eststo
}

esttab  using "appendix9.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.10: Triple differenced

eststo clear
foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap  c.interaction c.postduterte#c.tight postduterte c.interaction#c.tight  , fe vce(cl municipality)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2  {
xtreg `y'  c.interaction c.postduterte#c.tight postduterte c.interaction#c.tight  , fe vce(cl municipality)
eststo
}

esttab  using "appendix10.tex", keep(interaction c.interaction#c.tight) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50)

*** Table A.11: Alternative period cutoff (May 10, 2016; day after election day, when Roxas conceded)

use "figurea11_data",clear

eststo clear
foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap interaction postconcession if tight==1, fe vce(cl municipality)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2 {
xtreg `y' interaction postconcession if tight==1, fe vce(cl municipality)
eststo
}

esttab  using "appendix11.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 


*** Table A.12: Excluding NCR
use "RSH-main.dta",clear
gen NCR=(regexm(region_province_municipality_cit,"NCR"))

eststo clear
foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap interaction postduterte if tight==1 & NCR==0, fe vce(cl municipality)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2  {
xtreg `y' interaction postduterte if tight==1 & NCR==0, fe vce(cl municipality)
eststo
}

esttab  using "appendix12.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.13: Rotating dropping parties (Bantay Krimen)
use "RSH-main.dta",clear

eststo clear 
foreach party in IND PDPLBN NUP UNA NP NPC      {
xtreg drug_related_pcap interaction postduterte if tight==1 & party!="`party'", fe vce(cl municipality)
eststo
}

esttab  using "appendix13.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.14: Rotating dropping parties (Fatal ACLED PNP)

eststo clear
foreach party in IND PDPLBN NUP UNA NP NPC      {
xtreg fatal_pnp2 interaction postduterte if tight==1 & party!="`party'", fe vce(cl municipality)
eststo
}

esttab  using "appendix14.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Figure A.1: Cattaneo et al. (2018) Local Polynomial Manipulation Test

rddensity lp_vote_share_margin

*** Table A.15: IK bandwidth

eststo clear
foreach y in drug_related assault theft total_nodrug {
rdrobust `y'_pcap_diff unaligned_vote_share_margin , all  bwselect(IK)
eststo
}

esttab  using "appendix15.tex", rename(Bias-corrected rdd_estimate) keep(rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.16: No bias correction, conventional errors
eststo clear
foreach y in drug_related assault theft total_nodrug {
rdrobust `y'_pcap_diff unaligned_vote_share_margin , all
eststo
}

esttab  using "appendix16.tex", rename( Conventional rdd_estimate) keep(rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.17: Bias-corrected with robust variance estimator

eststo clear
foreach y in drug_related assault theft total_nodrug {
rdrobust `y'_pcap_diff unaligned_vote_share_margin , all
eststo
}

esttab  using "appendix17.tex", rename( Robust rdd_estimate) keep(rdd_estimate) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 


*** Table A.18:  Two percent margin for difference-in-differences

eststo clear
foreach y in drug_related theft assault homicide robbery rape  {
xtreg `y'_pcap interaction postduterte if verytight==1, fe vce(cl municipality)
margins, at(interaction=(0) postduterte=(1))
eststo
}

esttab  using "appendix18.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.19: ANCOVA with 5 percent margin

eststo clear
foreach y in drug_related theft assault homicide robbery rape  {
reg `y'_pcap non_establishment_mayor L.`y'_pcap i.region2 if tight==1, robust
eststo
}

esttab  using "appendix19.tex", keep(non_establishment_mayor) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.20: 2013 electoral cycle
use  "figurea20_data",clear

eststo clear
reg reelect1 non_establishment_mayor i.region2 if sample==1 , robust
eststo

esttab using "appendix20.tex", keep(non_establishment_mayor) cells(b(star fmt(2)) se(par fmt(2))) ///
  scalars("N N" "N_g Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.21: Comparing Analytic errors with Randomization inference and Bootstrapping

use "RSH-main.dta",clear

*** Outcome: drug-related

xtreg drug_related_pcap interaction postduterte if tight==1, fe vce(cl municipality)

ritest interaction _b[interaction], reps(1000) seed(125):  xtreg drug_related_pcap interaction postduterte if tight==1, fe vce(cl municipality)

xtreg drug_related_pcap interaction postduterte if tight==1, fe vce(bootstrap, reps(500) seed(125))

*** Outcome: Fatal ACLED 

xtreg fatal_acled2 interaction postduterte if tight==1, fe vce(cl municipality)

ritest interaction _b[interaction], reps(1000) seed(125):  xtreg fatal_acled2 interaction postduterte if tight==1, fe vce(cl municipality)

xtreg fatal_acled2 interaction postduterte if tight==1, fe vce(bootstrap, reps(500) seed(125))


*** Figure A.3: RDD Plots


twoway lpolyci drug_related_pcap_diff unaligned_vote_share_margin if unaligned_vote_share_margin<0 & unaligned_vote_share_margin>-.2, pw(.4)  k(epan2) level(80) || ///
lpolyci drug_related_pcap_diff unaligned_vote_share_margin if  unaligned_vote_share_margin>0 & unaligned_vote_share_margin<.2, pw(.4) k(epan2) xline(0) level(80) ///
legend(order(2 1 ) label(2 "Local linear polynomial trend") label(1 "Confidence interval" )) xtitle("Margin of victory (Outsider candidate)") ytitle("Drug-related incidents per capita (differenced)") title("Drug-related")
graph export "drugrelateddiff.pdf", as(pdf) replace

twoway lpolyci total_nodrug_pcap_diff unaligned_vote_share_margin if unaligned_vote_share_margin<0 & unaligned_vote_share_margin>-.2, pw(.4)  k(epan2) level(80) || ///
lpolyci total_nodrug_pcap_diff unaligned_vote_share_margin if  unaligned_vote_share_margin>0 & unaligned_vote_share_margin<.2, pw(.4) k(epan2) xline(0) level(80) ///
legend(order(2 1 ) label(2 "Local linear polynomial trend") label(1 "Confidence interval" )) xtitle("Margin of victory (Outsider candidate)") ytitle("Non-drug incidents per capita (differenced)") title("Non drug-related")
graph export "nondrugdiff.pdf", as(pdf) replace

twoway lpolyci fatal_pnp2_diff unaligned_vote_share_margin if unaligned_vote_share_margin<0 & unaligned_vote_share_margin>-.2, pw(.4)  k(epan2) level(80) || ///
lpolyci fatal_pnp2_diff unaligned_vote_share_margin if  unaligned_vote_share_margin>0 & unaligned_vote_share_margin<.2, pw(.4) k(epan2) xline(0) level(80) ///
legend(order(2 1 ) label(2 "Local linear polynomial trend") label(1 "Confidence interval" )) xtitle("Margin of victory (Outsider candidate)") ytitle("Fatal PNP incidents (differenced)") title("Fatal PNP incidents")
graph export "acledpnpdiff.pdf", as(pdf) replace

twoway lpolyci fatal_vigilante2 unaligned_vote_share_margin if unaligned_vote_share_margin<0 & unaligned_vote_share_margin>-.2, pw(.4)  k(epan2) level(80) || ///
lpolyci fatal_vigilante2 unaligned_vote_share_margin if  unaligned_vote_share_margin>0 & unaligned_vote_share_margin<.2, pw(.4) k(epan2) xline(0) level(80) /// 
legend(order(2 1 ) label(2 "Local linear polynomial trend") label(1 "Confidence interval" )) xtitle("Margin of victory (Outsider candidate)") ytitle("Fatal Vigilante incidents (differenced) ") title("Fatal vigilante incidents")
graph export "acledvigdiff.pdf", as(pdf) replace

*** Table A.22:  PLACEBO 1: Pre-Duterte Crime Outcomes

eststo clear
foreach y in drug_related assault theft total_nodrug   {
reg `y'_pcap non_establishment_mayor  i.region2   if tight==1 & postduterte==0, robust
eststo `y' 
}

foreach y in drug_related assault theft total_nodrug {
rdrobust `y'_pcap unaligned_vote_share_margin if postduterte==0  , all
eststo
}

esttab  using "appendix22.tex", rename(Bias-corrected rdd_estimate) keep(rdd_estimate non_establishment_mayor) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters" "h_bw Optimal Bandwidth")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 


*** Table A.23: PLACEBO 2: 2010 Census characteristics

eststo clear
foreach y in population2010 male hhsize ofw education age1839 {
reg `y' non_establishment_mayor i.region2 if postduterte==0 & tight==1, robust
eststo
}
esttab  using "appendix23a.tex", keep(non_establishment_mayor) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 
  
eststo clear
foreach y in  mssingle relrc relislam ip homegood{
reg `y' non_establishment_mayor i.region2 if postduterte==0 & tight==1, robust
eststo
}
esttab  using "appendix23b.tex", keep(non_establishment_mayor) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 


*** Table A.24: Bandwidth variation for robustness (DiD)

eststo clear
foreach b in .06 .055 .05 .045 .04 .035 .02{
	xtreg drug_related_pcap interaction postduterte if abs(lp_vote_share_margin)<=`b', fe vce(bootstrap, reps(500) seed(125))
	eststo
}

esttab  using "appendix24.tex", rename(interaction DiD_estimate) keep(DiD_estimate ) cells(b(star fmt(2)) se(par fmt(2))) ///
  scalars("N N" "N_clust Clusters" )  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.25: Candidate background characteristics

use "table25_data",clear

eststo clear
foreach y in vertical_imt mun_dyn_pat_mem mun_dyn_mat_mem female first_MAYOR_elec first_MAYOR_win {
reg `y' non_establishment_mayor i.region2 if tight==1 & winner==1, robust

eststo
}
esttab  using "appendix25.tex", keep(non_establishment_mayor) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.26: LP mayor balance and vote share in previous election cycle

use "table26_data",clear

eststo clear
reg lp_mayor2013 non_establishment_mayor  if tight==1, robust
eststo
reg vshare_official_2013 non_establishment_mayor if tight==1, robust
eststo

esttab  using "appendix26.tex", keep(non_establishment_mayor) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.27: Spatial Results 1: Effect on neighboring.

use "RSH-main.dta",clear

eststo clear

foreach y in drug_related assault theft total_nodrug  {
xtreg `y'_pcap  c.postduterte#c.neigh_nonestab   postduterte  if neig_sampl==1, fe vce(cl spatial_muni_cluster)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2 {
xtreg `y' c.postduterte#c.neigh_nonestab  postduterte  if neig_sampl==1, fe vce(cl spatial_muni_cluster)
eststo
}
esttab  using "appendix27.tex", keep(c.postduterte#c.neigh_nonestab) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.28: Effects on Crime; Excluding Units with Treated Neighbors

eststo clear

foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap interaction  postduterte  if tight==1 & neig_sampl2==0, fe vce(cl municipality)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2     {
xtreg `y' interaction postduterte  if tight==1 & neig_sampl2==0, fe vce(cl municipality)
eststo
}

esttab  using "appendix28.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.29: Spatial Results 3: Clustering SE by province
eststo clear

foreach y in drug_related assault theft total_nodrug {
xtreg `y'_pcap interaction  postduterte  if tight==1 , fe vce(cl prov_id)
eststo
}

foreach y in fatal_acled2  fatal_pnp2  fatal_vigilante2     {
xtreg `y' interaction postduterte  if tight==1 , fe vce(cl prov_id)
eststo
}

esttab  using "appendix29.tex", keep(interaction) cells(b(star fmt(2)) se(par fmt(2))) ///
scalars("N N" "N_clust Clusters")  starlevel(* .05 ** .01 *** .001) replace tex nolz label noobs noabb wrap varwidth(50) 

*** Table A.32: Party of 2016 Mayoral Winners

use "RSH-main.dta",clear
tab party if postd==0




